{extend name='view/common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
<input type="hidden" name="table_status" id="table_status" value="1">
<input type="hidden" name="pk_id" id="pk_id" value="data_id">
{if condition="$info.app_id eq ''"}
<input type="hidden" name='app_id' id='app_id' value="{$app_id}" />
{/if}
<input type="hidden" name='menu_id' id='menu_id' value="{$info.menu_id}" />
	<div class="ibox-content layui-form">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row" style="margin-top:-20px;">
				<div class="layui-tab layui-tab-brief" lay-filter="test">
					<div class="layui-tab-content" style="margin-top:10px;">
						<div class="layui-tab-item layui-show">
							<div class="col-sm-12">
							<!-- form start -->
								<div class="form-group">
									<label class="col-sm-2 control-label">模型名称：</label>
									<div class="col-sm-9">
										<input type="text" autocomplete="off" id="title" value="{$info.title}" name="title" class="form-control" placeholder="请输入菜单名称">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">数据库表名：</label>
									<div class="col-sm-9">
										<input type="text" id="table_name" value="{$info.table_name}" name="table_name" class="form-control" placeholder="请输入数据库表名">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">状态：</label>
									<div class="col-sm-9">
									<?php if(!isset($info['status'])){ $info['status'] = 1; }; ?>
										<input name="status" value="1" type="radio" {if condition="$info.status eq 1"}checked{/if}  title="正常">
										<input name="status" value="0" type="radio" {if condition="$info.status eq 0"}checked{/if}  title="禁用">
									</div>
								</div>
							<!-- form end -->
							</div>
						</div>
						
					</div>
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="{if condition="$info.app_id neq ''"}CodeInfoDlg.update(){else/}CodeInfoDlg.add(){/if}" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js?t=1498856285724" charset="utf-8"></script>
<script>
layui.use(['form'], function () {
	window.form = layui.form;
});
layui.use('element', function(){
	var element = layui.element;
	element.on('tab(test)', function(elem){});
});

var CodeInfoDlg = {
	CodeInfoData: {},
	deptZtree: null,
	pNameZtree: null,
	validateFields: {
		title: {
			validators: {
				notEmpty: {
					message: '菜单标题不能为空'
	 			}
	 		}
	 	},
		controller_name: {
			validators: {
				regexp: {
					regexp: /^[0-9a-zA-Z/]+$/,
					message: '大小写字母组合'
	 			},
	 		}
	 	},
		table_name: {
			validators: {
				regexp: {
					regexp: /^[a-zA-Z_0-9]+$/,
					message: '大小写字母组合'
	 			},
	 		}
	 	},
		pk_id: {
			validators: {
				regexp: {
					regexp: /^[a-zA-Z_]+$/,
					message: '大小写字母组合'
	 			},
	 		}
	 	}
		
	 }
}


CodeInfoDlg.clearData = function () {
	 this.CodeInfoData = {};
};


CodeInfoDlg.set = function (key, val) {
	 this.CodeInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
	 return this;
};


CodeInfoDlg.get = function (key) {
	 return $("#" + key).val();
};


CodeInfoDlg.close = function () {
	 var index = parent.layer.getFrameIndex(window.name);
	 parent.layer.close(index);
};


CodeInfoDlg.collectData = function () {
	this.set('menu_id').set('title').set('controller_name').set('table_name').set('pk_id').set('sortid').set('pid').set('url').set('menu_icon').set('tab_menu').set('app_id').set('upload_config_id');
};


CodeInfoDlg.icon = function () {
		var index = layer.open({type: 2,title: '设置图标',area: ['800px', '500px'],fix: false, maxmin: true,content: Feng.ctxPath + '/Base/icon/field/menu_icon'});
		this.layerIndex = index;
}


CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 
	 var is_create = $("input[name = 'is_create']:checked").val();
	 var is_url = $("input[name = 'is_url']:checked").val();
	 var table_status = $("input[name = 'table_status']:checked").val();
	 var status = $("input[name = 'status']:checked").val();
	 var is_submit = $("input[name = 'is_submit']:checked").val();
	 
	 var tip = '添加';
	 var ajax = new $ax(Feng.ctxPath + "/Sys.Menu/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(tip + "成功" );
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(tip + "失败！" + data.msg + "！");
		 }
	 }, function (data) {
	 	Feng.error("操作失败!" + data.responseJSON.message + "!");
	 });
	 ajax.set('is_create',is_create);
	 ajax.set('is_url',is_url);
	 ajax.set('table_status',table_status);
	 ajax.set('status',status);
	 ajax.set('is_submit',is_submit);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


CodeInfoDlg.update = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 
	 var is_create = $("input[name = 'is_create']:checked").val();
	 var is_url = $("input[name = 'is_url']:checked").val();
	 var table_status = $("input[name = 'table_status']:checked").val();
	 var status = $("input[name = 'status']:checked").val();
	 var is_submit = $("input[name = 'is_submit']:checked").val();
	 
	 var tip = '修改';
	 var ajax = new $ax(Feng.ctxPath + "/Sys.Menu/update", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(tip + "成功" );
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(tip + "失败！" + data.msg + "！");
		 }
	 }, function (data) {
	 	Feng.error("操作失败!" + data.responseJSON.message + "!");
	 });
	 ajax.set('is_create',is_create);
	 ajax.set('is_url',is_url);
	 ajax.set('table_status',table_status);
	 ajax.set('status',status);
	 ajax.set('is_submit',is_submit);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


CodeInfoDlg.validate = function () {
	  $('#CodeInfoForm').data("bootstrapValidator").resetForm();
	  $('#CodeInfoForm').bootstrapValidator('validate');
	  return $("#CodeInfoForm").data('bootstrapValidator').isValid();
};


$(function () {
	   Feng.initValidator("CodeInfoForm", CodeInfoDlg.validateFields);
});

</script>


{/block}
